//
//  LogoutAlertView.m
//  BaseAPP
//
//  Created by Evisu on 16/12/17.
//  Copyright © 2016年 evisum. All rights reserved.
//

#import "LogoutAlertView.h"

@interface LogoutAlertView ()

@property (nonatomic, strong)UILabel *labDesc;

@property (nonatomic, strong)UIView *vLine1;

@property (nonatomic, strong)UIButton *btnLogout;

@property (nonatomic, strong)UIView *vGrayView;

@property (nonatomic, strong)UIButton *btnCancel;

@end

@implementation LogoutAlertView

- (instancetype)init {

    if (self = [super init]) {
        
        [self initViews];
        [self layoutViews];
    }
    
    return self;
}

- (void)initViews {

    self.backgroundColor = [UIColor whiteColor];
    
    self.labDesc = [[UILabel alloc] init];
    self.labDesc.text = @"退出后不会删除任何历史数据，下次登录依然可以使用本账号。";
    self.labDesc.numberOfLines = 0;
    self.labDesc.textAlignment = NSTextAlignmentCenter;
    self.labDesc.font = [UIFont systemFontOfSize:14.0];
    self.labDesc.textColor = HEXColor(@"989898");
    
    self.vLine1 = [[UIView alloc] init];
    self.vLine1.backgroundColor = HEXColor(@"ececee");
    
    self.btnLogout = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.btnLogout setTitle:@"退出登录" forState:UIControlStateNormal];
    [self.btnLogout setTitleColor:HEXColor(@"dd3439") forState:UIControlStateNormal];
    [self.btnLogout setBackgroundImage:[UIImage imageWithColor:HEXColor(@"F3F2F7")] forState:UIControlStateHighlighted];
    [self.btnLogout addTarget:self action:@selector(didClickedLogoutBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    self.vGrayView = [[UIView alloc] init];
    self.vGrayView.backgroundColor = HEXColor(@"ebeaef");
    
    self.btnCancel = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.btnCancel setTitle:@"取消" forState:UIControlStateNormal];
    [self.btnCancel setTitleColor:HEXColor(@"242426") forState:UIControlStateNormal];
    [self.btnCancel setBackgroundImage:[UIImage imageWithColor:HEXColor(@"F3F2F7")] forState:UIControlStateHighlighted];
    [self.btnCancel addTarget:self action:@selector(didClickedCancelBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubview:self.labDesc];
    [self addSubview:self.vLine1];
    [self addSubview:self.btnLogout];
    [self addSubview:self.vGrayView];
    [self addSubview:self.btnCancel];
}


- (void) layoutViews {
    
   CGSize descSize = [self.labDesc.text boundingRectWithSize:CGSizeMake(272, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14.0]} context:nil].size;
    
    self.labDesc.sd_layout
    .topSpaceToView(self, 22)
    .centerXEqualToView(self)
    .widthIs(272)
    .heightIs(descSize.height);
    [self.labDesc setMaxNumberOfLinesToShow:0];
    
    self.vLine1.sd_layout
    .leftEqualToView(self)
    .rightEqualToView(self)
    .topSpaceToView(self.labDesc, 22)
    .heightIs(1);
    
    self.btnLogout.sd_layout
    .centerXEqualToView(self)
    .topEqualToView(self.vLine1)
    .leftEqualToView(self)
    .rightEqualToView(self)
    .heightIs(48);
    
    self.vGrayView.sd_layout
    .topSpaceToView(self.btnLogout, 0)
    .leftEqualToView(self)
    .rightEqualToView(self)
    .heightIs(6);
    
    self.btnCancel.sd_layout
    .centerXEqualToView(self)
    .bottomEqualToView(self)
    .leftEqualToView(self)
    .rightEqualToView(self)
    .heightIs(48);
    
}

//退出登录
- (void)didClickedLogoutBtn:(UIButton *)btn {
    
    if (self.logoutBlock) {
        
        self.logoutBlock();
    }
}

//取消
- (void)didClickedCancelBtn:(UIButton *)btn {

    if (self.cancelBlock) {
        
        self.cancelBlock();
    }
}

@end
